package org.judo.generate.mvc;

public class HeaderParser implements Parser
{
	ViewResult viewResult;
	private String curStatement;
	
	public ViewResult getViewResult()
	{
		return viewResult;
	}

	public void setViewResult(ViewResult viewResult)
	{
		this.viewResult = viewResult;
	}
	
	public Parser getNestedParser()
	{
		return null;
	}

	public boolean isFinished()
	{
		if (curStatement != null)
			if (curStatement.equals("/headers"))
				return true;
				
		return false;
	}

	public boolean needsNestedParser()
	{
		return false;
	}

	public void parseNextLine(String line) throws ParseException
	{
		curStatement = line;
		
		if (line.startsWith("/header"))
		{
			viewResult.html += "\t\t\t</tr>\n";
		}
		else if (line.equals(""))
		{
		}
		else if (line.startsWith("#"))
		{
		}
		else
		{
			String header = line;
			
			String width = "*";
			String display = null;
			
			if (header.contains(","))
			{
				String parts[] = header.split(",");
				display = parts[0].trim();
				width = parts[1].trim();
			}
			else
				display = header;
			
			viewResult.html += "\t\t\t\t<td width=\""+width+"\">"+display+"</td>\n";
		}
		
	}

	public void setInitLine(String line) throws ParseException
	{
		viewResult.html += "\t\t\t<tr class=\"standardTBLHeader\">\n";
	}

}
